package com.hmall.order.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hmall.order.service.IOrderDetailService;
import com.hmall.order.service.impl.OrderDetailService;
import com.hmall.pojo.OrderDetail;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order_detail")
@Slf4j
public class OrderDetailController {
    @Autowired
    private IOrderDetailService iOrderDetailService;

    /**
     * 根据orderId查询orderDetail信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public OrderDetail queryOrderDetail(@PathVariable("id") Long id){
        LambdaQueryWrapper<OrderDetail> lqw = new LambdaQueryWrapper<>();
        lqw.select(OrderDetail::getNum,OrderDetail::getPrice,OrderDetail::getItemId);//拿到商品数量、商品id、金额
        lqw.eq(OrderDetail::getOrderId,id);
        OrderDetail orderDetail = iOrderDetailService.getOne(lqw);
        return orderDetail;
    }
}
